/**
 * 用户编辑 add by gsh
 * @param frm
 * @returns
 */
function checkData(frm){
	var isValid = validator(frm);

	return isValid;	
}

FormValid.showError = function(errMsg, errName, formName) {
    for (key in FormValid.allName) {
        var jctr = $('#errMsg_' + FormValid.allName[key]);
        jctr.removeClass("red").hide();           
    }

    for (key in errMsg) {
        var jctr = $('#errMsg_' + errName[key]);
        jctr.addClass("red").show();
    }
};



$(function(){
	$("#txtPName").blur(function(){
		var userName=this.value;
		userName=$.trim(userName);
		if(userName=="")return;
		var jctr = $('#errMsg_pName');
		if(userName==null || $.trim(userName)==""){
	        jctr.addClass("red").show();			
	        jctr.text("请输入用户名");
		}
		$.ajax({
			type : "POST",
			url : "/user/exists",
			data:"userName="+$.trim(userName),
			dataType : "json",
			success : function(msg) {				
				var imgValid=$("#imgValid");
				imgValid.removeClass("hide");
				if (msg.code == "200"){
					imgValid.attr("src","/res/images/right.png");
					jctr.removeClass("red").show();			
					jctr.text("正确，用户手机号："+msg.data.mobile);	
				}
				else if (msg.code == "400"){
					imgValid.attr("src","/res/images/error.png");
					jctr.addClass("red").show();			
					jctr.text(msg.data.mobile);	
				}
			}
		});		
	}).keydown(function(){
		var imgValid=$("#imgValid");
		imgValid.addClass("hide");	
		var jctr = $('#errMsg_pName');
		jctr.text("请输入推荐人").removeClass("red").show();	
	});
	
});

function saveCallback(data){
	if(data!=null && data.indexOf("不存在")>0){
		var imgValid=$("#imgValid");
		imgValid.removeClass("hide");
		imgValid.attr("src","/res/images/error.png");
		var jctr = $('#errMsg_userName');
		jctr.addClass("red").show();	
		jctr.text(data);	
	}
}